<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:set var="pageTitle" value="新增附件" />
<%@ include file="../inc/Title.jsp"%>
<head>
<link rel="stylesheet" type="text/css" href="/css/base.css" />
<script src="/js/popup_ext.js"></script>
<script language="javascript">
	function doSave(){
		var customPath=document.getElementById("customPath").value.trim();
		var customMark=document.getElementById("customMark").value.trim();
		var i;
		var hasFile=false;
		for(i=1;i<6;i++){
			var fn=document.getElementById("fileName"+i).value.trim();
			var wcId=document.getElementById("extId"+i).value;
			var accType;
			if(document.getElementById("accType"+i+"_1").checked){
				accType="DESIGN";
			}else if(document.getElementById("accType"+i+"_2").checked){
				accType="COOPER";
			}else{
				accType="CONTRACT";
			}
			
			if(fn!=""){
				var lowerFn=fn.toLowerCase();
				if(lowerFn.endWith(".exe") || lowerFn.endWith(".bat") || lowerFn.endWith(".com") || lowerFn.endWith(".jsp") || lowerFn.endWith(".htm") || lowerFn.endWith(".html")){
					ShowAlert('提示框','不能上传.exe、.bat、.com、.jsp、.htm或.html格式的文件！',200,100);
					return;
				}else if(accType=="DESIGN" && (wcId=="" || wcId=="0")){
					ShowAlert('提示框','请选择工作中心！',200,100);
					return;
				}
				document.getElementById("hid_file_name"+i).value=fn;
				hasFile=true;
			}
		}
		
		if(hasFile){
			document.getElementById("upload_type").value="UPLOAD";
			
			document.getElementById("bodyDiv").style.display="none";
			document.getElementById("postframe").height="100%";
			document.getElementById("postframe").style.display="";
			frm.submit();
		}else if(customPath!=""){
			var wcId=document.getElementById("extId").value;
			var accType;
			if(document.getElementById("at_1").checked){
				accType="DESIGN";
			}else if(document.getElementById("at_2").checked){
				accType="COOPER";
			}else{
				accType="CONTRACT";
			}
			if(accType=="DESIGN" && (wcId=="" || wcId=="0")){
				ShowAlert('提示框','请选择工作中心！',200,100);
				return;
			}else{
				document.getElementById("upload_type").value="PATH";
				document.getElementById("accType").value=accType;
				
				document.getElementById("bodyDiv").style.display="none";
				document.getElementById("postframe").height="100%";
				document.getElementById("postframe").style.display="";
				frm.submit();
			}
		}else{
			ShowAlert('提示框','请选择要上传的文件，或输入资料路径！',200,100);
			return;
		}
	}
	function doCancel(){
		parent.ClosePop();
	}
	function showMe(){
		if(checkNavigator()[0]!="msie"){
			for(var i=1;i<6;i++){
				document.getElementById("fileName"+i).className="";
			}
		}
	}
	function selectAccMark(objId){
		var url="/base/AccessoryMarkListForSelect.ihtm";
		ShowIframe("选择文件说明",url,500,400,"selectAccMarkCallBack('"+objId+"')");
	}
	function selectAccMarkCallBack(objId){
		if(popRetVal!=null && popRetVal!=""){
			document.getElementById(objId).value=popRetVal;
		}
	}
	function browseFolder(){
		try{
			var shell = new ActiveXObject("Shell.Application");
			var folder = shell.BrowseForFolder(0, "请选择目录", 64, 17);//起始目录为：我的电脑
			//var folder = shell.BrowseForFolder(0,"请选择目录",0); //起始目录为：桌面
			if(folder!=null){
				folder = folder.items(); // 返回 FolderItems 对象
            	folder = folder.item(); // 返回 Folderitem 对象
            	folder = folder.Path;   // 返回路径
            	if (folder.charAt(folder.length - 1) != "\\") {
                	folder = folder + "\\";
            	}
            	document.getElementById("customPath").value = folder;
			}
		}catch(e){
			ShowAlert('提示框',e.message,200,100);
		}
	}
	function changePathAccType(){
		if(!document.getElementById("at_1").checked){
			document.getElementById("extId").options[0].selected=true;
		}
	}
	function changeFileAccType(index){
		if(!document.getElementById("accType"+index+"_1").checked){
			document.getElementById("extId"+index).options[0].selected=true;
		}
	}
	function doWcChange(index){
		var si=document.getElementById("extId"+index).selectedIndex;
		for(var i=index;i<=5;i++){
			document.getElementById("extId"+i).selectedIndex=si;
		}
	}
</script>
</head>
<body oncontextmenu="return false" scroll="no" onLoad="showMe();" class="sheet modal-dialog" style=" padding-top:10px;">
<div class="sheet-main"  style="width:830px;" id="bodyDiv">
	<form name="frm" method="post" action="AccessoryMultiNew.ihtm" enctype="multipart/form-data">
	<div class="sheet-list" style="width:100%;">
	  <div class="modal-main search-business">
	  	<div style="width:100%;">
			<c:set var="pageTopTitle" value="新增附件" />
			<%@ include file="../inc/PageTop.jsp"%>
			<table border="0" cellspacing="1" cellpadding="1" align="center" class="table-a" >
			</table>
			<fieldset class="det_fieldset ">
				<legend class="mag10">第一种方式：不传文件，只登记文件存储路径</legend>
				<table border="0" cellspacing="1" cellpadding="1" align="center" class="table-0" >
					<tr>
			      		<th style="width:10%">存储路径：</th>
				      	<td style="width:26%">
				      		<input type="text" style="width:150px" maxlength="100" name="customPath" id="customPath" class="TextBox">
				      		<input type="button" value="..." onClick="browseFolder();">
				     	</td>
				      	<th style="width:10%">文件说明：</th>
				      	<td style="width:54%">
				      		<input type="text" maxlength="50" name="customMark" id="customMark" class="TextBox">
				      		<img class="make-a" src="/images/make-a.gif" onClick="selectAccMark('customMark');" style="cursor:pointer;" />
				      		<select name='extId' id='extId' style="width:80px">
				      			<option value="0">==请选择==</option>
								<c:forEach var="wcItem" items="${wcList}" varStatus="extIdIndex">
									<option value="${wcItem.id}" <c:if test="${accType!='COOPER' && (extId==0 && extIdIndex.index==0 || extId!=0 && wcItem.id==extId)}">selected</c:if>>${wcItem.wcName}</option>
								</c:forEach>
				  			</select>
							<input type="radio" name="acc_type" id="at_1" <c:if test="${accType!='COOPER'}">checked="true"</c:if> onClick="changePathAccType();">自制
							<input type="radio" name="acc_type" id="at_2" <c:if test="${accType=='COOPER'}">checked="true"</c:if> onClick="changePathAccType();">外协
							<input type="radio" name="acc_type" id="at_3" onClick="changePathAccType();">合同
							<input type="hidden" name="accType" id="accType" value="">
				     	</td>
					</tr>
				</table>
			</fieldset>
			
			<div class="blank12"></div>
			<fieldset class="det_fieldset ">
				<legend class="mag10">第二种方式：上传到服务器</legend>
				<table border="0" cellspacing="1" cellpadding="1" align="center" class="table-0" >
					<colgroup>
	        			<col width=10%></col>
	        			<col width=26%></col>
	        			<col width=10%></col>
	        			<col width=54%></col>
	    			</colgroup>
					<c:forEach var="item" begin="1" end="5" step="1">
					<tr>			   	
				      	<th>文件名称：</th>
				      	<td>
							<input type="file" style="width:174px" name="fileName${item}" id="fileName${item}" class="TextBox">
							<input type="hidden" id="hid_file_name${item}" name="hid_file_name${item}" >
				     	</td>
						<th>文件说明：</th>
				      	<td>
				      		<input type="text" maxlength="50" name="mark${item}" id="mark${item}" class="TextBox">
				      		<img class="make-a" src="/images/make-a.gif" onClick="selectAccMark('mark${item}');" style="cursor:pointer;" />
							<select name='extId${item}' id='extId${item}' style="width:80px" onChange="doWcChange(${item});">
								<option value="0">==请选择==</option>
								<c:forEach var="wcItem" items="${wcList}" varStatus="extIdIndex">
								<option value="${wcItem.id}" <c:if test="${accType!='COOPER' && (extId==0 && extIdIndex.index==0 || extId!=0 && wcItem.id==extId)}">selected</c:if>>${wcItem.wcName}</option>
								</c:forEach>
				  			</select>
							<input type="radio" name="accType${item}" id="accType${item}_1" value="DESIGN" <c:if test="${accType!='COOPER'}">checked="true"</c:if> onClick="changeFileAccType(${item});">自制
							<input type="radio" name="accType${item}" id="accType${item}_2" value="COOPER" <c:if test="${accType=='COOPER'}">checked="true"</c:if> onClick="changeFileAccType(${item});">外协
							<input type="radio" name="accType${item}" id="accType${item}_3" value="CONTRACT" onClick="changeFileAccType(${item});">合同
				     	</td>
					</tr>
					</c:forEach>
				</table>
			</fieldset>
			</div>
		</div>
	</div>
	<div class="modal-buttom">
		<input type="button" class="buttom-a" value=" 上 传 " onClick="doSave();" >
		<input type="button" class="buttom-a" value=" 取 消 " onClick="doCancel();" >
		<input type="hidden" name="upload_type" id="upload_type" value="">
		<input type="hidden" name="agentId" id="agentId" value="${agentId}">
		<input type="hidden" name="agentType" id="agentType" value="${agentType}">
		<input type="hidden" name="code" id="code" value="${code}">
	</div>
	</form>
</div>
<iframe name="postframe" height="0" width="100%" frameborder="0" scrolling="no" style="display:none" id="postframe" src="/uploading.jsp"></iframe>
</body>
</html>